package com.example.hellocharts;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;

import java.util.ArrayList;
import java.util.List;

public class Main3Activity extends AppCompatActivity {
    private PieChart pic_chart;
//    private int[] piedata={8,24,35,23,10};
//    private int[] color={Color.parseColor("#356fb3"),
//            Color.parseColor("#000080"),Color.parseColor("#00BFFF"),
//            Color.parseColor("#00FF7F"),Color.parseColor("#FFEC8B")};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        pic_chart=findViewById(R.id.pic_chart);
        List<PieEntry> strings=new ArrayList<>();
        strings.add(new PieEntry(30f,""));
        strings.add(new PieEntry(50f,""));
        strings.add(new PieEntry(20f,""));

        PieDataSet dataSet=new PieDataSet(strings,"");


        ArrayList<Integer> colors=new ArrayList<Integer>();
        colors.add(getResources().getColor(R.color.Cyan2));
        colors.add(getResources().getColor(R.color.NavajoWhite));
        colors.add(getResources().getColor(R.color.LightSlateBlue));
        dataSet.setColors(colors);

        PieData pieData=new PieData(dataSet);
        pieData.setDrawValues(true);//显示值
        //把数字设为百分比
        pieData.setValueFormatter(new PercentFormatter());
        //设置字体大小
        pieData.setValueTextSize(12f);

        pic_chart.setData(pieData);
        pic_chart.invalidate();

        //把空心设为实心
        Description description = new Description();
        description.setText("");
        pic_chart.setDescription(description);
        //设半径为0
       // pic_chart.setHoleRadius(0f);
        //发现内圈还有个半透明的，再设置半透明的半径为0
        //pic_chart.setTransparentCircleRadius(0f);

        pic_chart.setCenterText("数据");

    }
}
